using System;
namespace ch.ethz.ssh2.packets
{
	
	/// <summary> PacketUserauthRequestPublicKey.
	/// 
	/// </summary>
	/// <author>  Christian Plattner
	/// </author>
	/// <version>  2.50, 03/15/10
	/// </version>
	public class PacketUserauthRequestPublicKey
	{
		virtual public byte[] Payload
		{
			get
			{
				if (payload == null)
				{
					TypesWriter tw = new TypesWriter();
					tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
					tw.writeString(userName);
					tw.writeString(serviceName);
					tw.writeString("publickey");
					tw.writeBoolean(true);
					tw.writeString(pkAlgoName);
					tw.writeString(pk, 0, pk.Length);
					tw.writeString(sig, 0, sig.Length);
					payload = tw.getBytes();
				}
				return payload;
			}
			
		}
		internal byte[] payload;
		
		internal System.String userName;
		internal System.String serviceName;
		internal System.String password;
		internal System.String pkAlgoName;
		internal byte[] pk;
		internal byte[] sig;
		
		public PacketUserauthRequestPublicKey(System.String serviceName, System.String user, System.String pkAlgorithmName, byte[] pk, byte[] sig)
		{
			this.serviceName = serviceName;
			this.userName = user;
			this.pkAlgoName = pkAlgorithmName;
			this.pk = pk;
			this.sig = sig;
		}
		
		public PacketUserauthRequestPublicKey(byte[] payload, int off, int len)
		{
			this.payload = new byte[len];
			Array.Copy(payload, off, this.payload, 0, len);
			
			TypesReader tr = new TypesReader(payload, off, len);
			
			int packet_type = tr.readByte();
			
			if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
				throw new System.IO.IOException("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")");
			
			throw new System.IO.IOException("Not implemented!");
		}
	}
}